package com.iflytek.springboot_medicine.service;

import com.iflytek.springboot_medicine.entity.Income;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.Date;


public interface IncomeRepository extends JpaRepository<Income, Integer> {
    @Query("SELECT i FROM Income i JOIN i.cate c " +
            "WHERE (:name IS NULL OR c.name = :name) " +
            "AND (:startDate IS NULL OR i.income_date >= :startDate) " +
            "AND (:endDate IS NULL OR i.income_date <= :endDate)")
    Page<Income> findByCategoryAndDateRange(
            @Param("name") String name,
            @Param("startDate") Date startDate,
            @Param("endDate") Date endDate,
            Pageable pageable
    );

    Income deleteById(int id);
}
